package org.hot100_1;

import java.util.HashMap;
import java.util.Map;

public class leetcode1 {
    public static int[] twoSum(int[] nums, int target) {
        int [] res = new int[2];
        Map<Integer,Integer> map = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i],i);
        }

        for (int i = 0; i < nums.length; i++) {
            int num =target-nums[i];
            if (map.containsKey(num) && map.get(num)!=i){
                res[0]=i;
                res[1]=map.get(target-nums[i]);
                return res;
            }
        }

        return res;
    }

    public static void main(String[] args) {
        int [] nums = {3,2,4};
        int[] res = twoSum(nums, 6);
        System.out.println(res[0]+"--"+res[1]);
    }
}
